<?php

namespace app\common\model;

use think\Model;
use app\common\model\Category;
use app\admin\model\Admin;
use think\Db;
class Articlenew extends Model
{

    

    

    // 表名
    protected $name = 'article';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;
    
 // 追加属性
    protected $append = [
        'jumptype',
        'newtypes',
        'adminame',
        'mystatus',
    ];
    public function getMystatusAttr($value,$data){
        if ($data['is_show']==0){
            return "审核中";
        }elseif ($data['is_show']==1){
            return "审核通过";
        }else{
            return "审核失败";
        }
    }
    public function getAdminameAttr($value,$data){
        return Admin::where('id',$data['admin_id'])->value('username');
    }
    public function getJumptypeAttr($value,$data){
        return Category::where($data['category_id'])->value('type');
    }
    public function getNewtypesAttr($value,$data){
        $newtypes=Category::where($data['category_id'])->value('type');
        $myname="";
        switch ($newtypes) {
            case 'default':
                $myname="链接";
                break;
            case 'article':
                $myname="文章";
                break;
            case 'article':
                $myname="图片";
                break;
            case 'article':
                $myname="文件下载";
                break;
            case 'article':
                $myname="详情";
                break;
            default:
                // code...
                break;
        }
        return $myname;
    }
    public function getCreatetimeAttr($value,$data){
        return date("Y-m-d",$value);

    }
    public function cate(){
        return $this->belongsTo(Category::class, 'category_id');

    }
    







}
